<?php
namespace app\api\controller;
use think\Db;
use app\admin\model\Config;
use app\common\model\School as SchoolModel;
use app\common\service\GuguService;
use think\Queue;

//志愿填报 智能填报
class Zhiyuan extends App
{
    
    public static function WhiteList()
    {
        return [
           
            'get_create_cj_pre',
			
        ];
    }
    
    public function get_create_cj_pre()
    {
        
		$province_id = $this->province_id;
		if(empty($province_id)){
			return $this->show(2001,"缺少province_id!", '');
		}
		
		$data['score_min'] = 100;
		$data['score_max'] = 750;
		$subject_mode = SchoolModel::getSubjectMode($province_id);	
		if($subject_mode == 2){
			$data['subjects1'] = ['物理','化学','生物','历史','地理','政治'];
			if($province_id == 801){
				$data['score_max'] = 660;
			}elseif($province_id == 933){
				$data['subjects1'] = ['物理','化学','生物','历史','地理','政治','技术'];
			}
			$data['subject_mode'] = 2;
		}elseif($subject_mode == 3){
			$data['subject_mode'] = 3;
			$data['subjects1'] = ['文科','理科'];
		}else{
			$data['subjects1'] = ['物理','历史'];
			$data['subjects2'] = ['化学','生物','地理','政治'];
			$data['subject_mode'] = 1;
		}
		if($province_id == 3206){
			$data['is_paiming'] = 1;
		}else{
			$data['is_paiming'] = 0;
		}
		return $this->show(1,"success", $data);
		
    }
    
    //保存成绩
    public function save_cj(){
        $user_id = $this->user_id;
		$province_id = $this->province_id;
        if($this->request->isPost()){
			
			$data['cj_subject_mode'] = $this->request->post("subject_mode",1,'intval');
			if(!in_array($data['cj_subject_mode'],[1,2,3])){
				return $this->show(2001,"subject_mode参数不正确!", '');
			}
			$data['cj_score'] = $this->request->post("score",0,'intval');
			$data['cj_subjects1'] = $this->request->post("subjects1",'','trim');
			$data['cj_subjects2'] = $this->request->post("subjects2",'','trim');
			
			if(empty($province_id)){
				return $this->show(2001,"缺少province_id!", '');
			}
			$member_province_id = Db::name("member")->where('id',$user_id)->value('province_id');
			if(!empty($member_province_id) && $province_id!=$member_province_id){
				return $this->show(2001,"请传个人资料里的省份!", '');
			}
			
			$subject_mode = SchoolModel::getSubjectMode($province_id);	
			if($data['cj_subject_mode'] != $subject_mode){
				return $this->show(2001,"subject_mode参数不正确!", '');
			}
			if($data['cj_score']<100){
				return $this->show(2001,"最低分100", '');
			}
			if($province_id == 801){
				if($data['cj_score']>660){
					return $this->show(2001,"最高分660", '');
				}
			}else{
				if($data['cj_score']>750){
					return $this->show(2001,"最高分750", '');
				}
			}
			if($subject_mode == 2){
				$cj_subjects1 = array_unique(explode('/',$data['cj_subjects1']));
				if(count($cj_subjects1)!=3){
					return $this->show(2001,"科目只能选3个!", '');
				}
				if(!empty($data['cj_subjects2'])){
					return $this->show(2001,"不能传次选科目!", '');
				}
				$cj_subjects = $data['cj_subjects1'];
				$data['cj_subject_mode_title'] = '综合';
			}elseif($subject_mode == 3){
				$cj_subjects1 = array_unique(explode('/',$data['cj_subjects1']));
				if(count($cj_subjects1)!=1){
					return $this->show(2001,"科目只能选1个!", '');
				}
				if(!empty($data['cj_subjects2'])){
					return $this->show(2001,"不能传次选科目!", '');
				}
				$cj_subjects = $data['cj_subjects1'];
				$data['cj_subject_mode_title'] = $data['cj_subjects1'];
			}else{
				if(empty($data['cj_subjects1']) || empty($data['cj_subjects2'])){
					return $this->show(2001,"请选择首选科目和次选科目!", '');
				}
				if($data['cj_subjects1'] !='物理' && $data['cj_subjects1'] !='历史'){
					return $this->show(2001,"首选科目只能选物理或历史!", '');
				}
				$cj_subjects2 = explode('/',$data['cj_subjects2']);
				if(count($cj_subjects2)!=2){
					return $this->show(2001,"次选科目必须只能选2个!", '');
				}
				$cj_subjects = $data['cj_subjects1'].'/'.$data['cj_subjects2'];
				$data['cj_subject_mode_title'] = $data['cj_subjects1'].'类';
			} 
			$data['is_cj'] = 1;
			$data['cj_subjects'] = $cj_subjects;
			$cj_subjects = explode('/',$cj_subjects);
			$SubjectList = SchoolModel::getSubjectList();
			foreach($cj_subjects as $vs){
				if(!in_array($vs,$SubjectList)) return $this->show(2001,"选取的科目不正确!", '');
			}
			
			
			$data['cj_rank'] = 0;
			//查询去年位次查询
			$year = date('Y',strtotime('-1 year'));
			$enrollprovince = Db::name("area")->where('id',$member_province_id)->value('name');
			//获取去年高考模式
			$subject_mode_rank = SchoolModel::getSubjectMode($province_id,$year);
			if($subject_mode_rank == 2){
				$subject_mode_rank_title = '综合';
			}elseif($subject_mode_rank == 3){
				if($data['cj_subject_mode_title'] == '物理类' || $data['cj_subject_mode_title'] == '理科'){
					$subject_mode_rank_title = '理科';
				}else{
					$subject_mode_rank_title = '文科';
				}
			}else{
				$subject_mode_rank_title = $data['cj_subject_mode_title'];
			} 
			$data['cj_subject_mode_title_2024'] = $subject_mode_rank_title;
			
			//获取前年高考模式
			$subject_mode_rank = SchoolModel::getSubjectMode($province_id,date('Y',strtotime('-2 year')));
			if($subject_mode_rank == 2){
				$subject_mode_rank_title2 = '综合';
			}elseif($subject_mode_rank == 3){
				if($data['cj_subject_mode_title'] == '物理类' || $data['cj_subject_mode_title'] == '理科'){
					$subject_mode_rank_title2 = '理科';
				}else{
					$subject_mode_rank_title2 = '文科';
				}
			}else{
				$subject_mode_rank_title2 = $data['cj_subject_mode_title'];
			} 
			$data['cj_subject_mode_title_2023'] = $subject_mode_rank_title2;
			
			$result = GuguService::make('/metadata/ceeline/one-score-one-section',['appkey'=>'CDZUAX7XAL84GKX9T96PULXVZMYLV8DQ','pageindex'=>1,'pagesize'=>100,'provincename'=>$enrollprovince,'subjectselection'=>$subject_mode_rank_title,'year'=>intval($year)]);
			if($result[0] != 200){
				return $this->show(2002,$result[1]??'error', '');
			}
			
			$list = $result[1][1];
			$page_total = ceil($result[1][0]['DataTotalCount']/100);
			if($page_total>1){
				for($i=2;$i<=$page_total;$i++){
					$result = GuguService::make('/metadata/ceeline/one-score-one-section',['appkey'=>'CDZUAX7XAL84GKX9T96PULXVZMYLV8DQ','pageindex'=>$i,'pagesize'=>100,'provincename'=>$enrollprovince,'subjectselection'=>$subject_mode_rank_title,'year'=>intval($year)]);
					if($result[0] != 200){
						return $this->show(2002,$result[1]??'error', '');
					}
					$list_temp = $result[1][1];
					$list = array_merge($list,$list_temp);
				}
			}
			foreach($list as $k=>$rs){
				$ExaminationScore = explode('-',$rs['ExaminationScore']);
				if(count($ExaminationScore)>1){
					$maxScore = $ExaminationScore[1];
					$minScore = $ExaminationScore[0];
				}else{
					$maxScore = $ExaminationScore[0];
					$minScore = $ExaminationScore[0];
				}
				$RankingRange = explode('-',$rs['RankingRange']);
				if(count($RankingRange)>1){
					$highestRank = $RankingRange[0];
					$LowestRank = $RankingRange[1];
				}else{
					$highestRank = $RankingRange[0];
					$LowestRank = $RankingRange[0];
				}
				if($data['cj_score']>($minScore-1) && $data['cj_score']<=($maxScore+1)){
					$data['cj_rank'] = $LowestRank;
				}
			}
			if($province_id == 3206){
				$data['cj_rank'] = $this->request->post("paiming",0,'intval');
				if(empty($data['cj_rank'])){
					return $this->show(2001, "请填写排名", "");
				}
			}else{
				if(empty($data['cj_rank'])){
					return $this->show(2001, "成绩创建失败，请联系管理员", "");
				}
			}
			
		
			$res = Db::name("member")->where('id',$user_id)->update($data);
			if( $res !== false ){
				Queue::push('app\job\ZhiyuanCache', [$user_id,$province_id], 'sp');
				return $this->show(1,"success", '');
			}else{
				return $this->show(2002, "fail", "");
			} 
		}else{
            return $this->show(2001, "非法请求", "");
        }
    }
	
	//获取成绩和选科
    public function get_my_cj()
    {
        
		$user_id = $this->user_id;
		$province_id = $this->province_id;
		if(empty($province_id)){
			return $this->show(2001,"缺少province_id!", '');
		}
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects1,cj_subjects2,cj_subjects,cj_subjects')->where('id',$user_id)->find();
		if($province_id!=$member['province_id']){
			return $this->show(2001,"请传个人资料里的省份!", '');
		}	
		$cj_subjects = explode('/',$member['cj_subjects']);
		$list= ['cj_score'=>$member['cj_score'],'cj_subjects1'=>$member['cj_subjects1'],'cj_subjects2'=>$member['cj_subjects2'],'subject'=>$cj_subjects];
		return $this->show(1,"成功", $list);
		
    }
	
	
    //获取批次列表
    public function get_batch_list()
    {
        
		$user_id = $this->user_id;
		$province_id = $this->province_id;
		if(empty($province_id)){
			return $this->show(2001,"缺少province_id!", '');
		}
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects1,cj_subjects2,cj_subject_mode_title_2024,cj_subject_mode_title_2023')->where('id',$user_id)->find();
		if($province_id!=$member['province_id']){
			return $this->show(2001,"请传个人资料里的省份!", '');
		}	
		
		$subject_mode = SchoolModel::getSubjectMode($province_id);	
		if($subject_mode == 2){
			$subject = '综合';
		}else{
			$subject = $member['cj_subjects1'];
		}
		
		$year = date('Y',strtotime("-1 year"));
		$year = 2025;
		if($year<2025){
			$subject = str_replace('类','',$member['cj_subject_mode_title_2024']);
		}else{
			if($subject_mode == 2){
				$subject = '综合';
			}else{
				$subject = $member['cj_subjects1'];
			}
		}
		//$subject = str_replace('类','',$member['cj_subject_mode_title_2024']);
		
		$batch_line1 = Db::name("batch_line")->where('batch_name','in','本科,本二,1段,本科B')->where('province_id',$province_id)->where('subject_name',$subject)->where('year',$year)->value('socre');
		//echo Db::name("batch_line")->getlastsql();
		$batch_line2 = Db::name("batch_line")->where('batch_name','in','专科,2段')->where('province_id',$province_id)->where('subject_name',$subject)->where('year',$year)->value('socre');
				
		$list[] = ['id'=>1,'batch_name'=>'本科','subject'=>$subject,'batch_line'=>$batch_line1??'_'];
		$list[] = ['id'=>2,'batch_name'=>'专科','subject'=>$subject,'batch_line'=>$batch_line2??'_'];
		return $this->show(1,"成功", $list);
		
    }
	
    public function get_score_range()
    {
		$user_id = $this->user_id;
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode')->where('id',$user_id)->find();
		$list['score_min_default'] = ($member['cj_score']-30<100)?100:$member['cj_score']-30;
		$list['score_max_default'] = ($member['cj_score']+20>750)?750:$member['cj_score']+20;
		$list['score_min'] = ($member['cj_score']-50<100)?100:$member['cj_score']-50;
		$list['score_max'] = ($member['cj_score']+50>750)?750:$member['cj_score']+50;
		
		return $this->show(1,"成功", $list);
	}
	
	//填报志愿
    public function get_school_list()
    {
		//dump(strlen('国家专项计划本科一批,国家专项计划本科批,本科一批次,提前本科批,普通本科批,本科A批,本科A段,本科B批,本科一批,本科一批A1段,本科一批A段,本科一批B段,本科一批H段,本科一批I段,本科一批U段,本科一批预科,本科一段,本科三批,本科三批A段,本科三批B段,本科专项计划批,本科二批,本科二批A段,本科二批B段,本科二批C段,本科二批K段,本科二批及预科,本科二段,本科批,本科批A段,本科批B段,本科批C段,本科批一段,本科提前批,本科提前批A段,本科提前批B段,本科提前批C,本科提前批C段'));die;
		
		
		$user_id = $this->user_id;
		$province_id = $this->province_id;
        $pagesize = 100;
        $page = $this->request->get("page",1,'intval'); 
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        
        $score_min = $this->request->get("score_min",0,'intval'); 
        $score_max = $this->request->get("score_max",0,'intval'); 
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim'); 
        $school_ids_1= $this->request->get("school_ids",'','trim'); 
        $cate_ids = $this->request->get("cate_ids",'','trim'); 
        $major_ids = $this->request->get("major_ids",'','trim');
		$major_ids1 = [];
		$major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
			$major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
		$major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
		$major_school_ids = [];
		if(!empty($major_ids)){
			foreach($major_ids as $km=>$vm){
				$major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
				$major_school_ids = array_merge($major_school_ids,$major_school_id);
				
			}
		}
		//dump($major_ids);die;
		
        if(!empty($province_ids)){
			$map['province_id'] = ['in',$province_ids];
        }
		/*
        if(!empty($school_type)){
			//$school_id1 = Db::name('school_type_data')->where('type_id','in',$school_type)->column('school_id');
			$school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
			$map['id'] = ['in',$school_id1];
        }
        if(!empty($school_tese)){
			$school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
			$map['id'] = ['in',$school_id2];
        }
        if(!empty($school_xingzhi)){
			//$school_id3 = Db::name('school_xingzhi_data')->where('xingzhi_id','in',$school_xingzhi)->column('school_id');
			$school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
			$map['id'] = ['in',$school_id3];
        }
		if(isset($school_id1) && isset($school_id2) && isset($school_id3)){
			$school_ids = array_intersect($school_id1,$school_id2,$school_id3);
			$map['id'] = ['in',$school_ids];
		}elseif(isset($school_id1) && isset($school_id2)){
			$school_ids = array_intersect($school_id1,$school_id2);
			$map['id'] = ['in',$school_ids];
		}elseif(isset($school_id1) && isset($school_id3)){
			$school_ids = array_intersect($school_id1,$school_id3);
			$map['id'] = ['in',$school_ids];
		}elseif(isset($school_id2) && isset($school_id3)){
			$school_ids = array_intersect($school_id2,$school_id3);
			$map['id'] = ['in',$school_ids];
		}*/
		if(!empty($school_type)){
			//$school_id1 = Db::name('school_type_data')->where('type_id','in',$school_type)->column('school_id');
			$school_id1 = Db::name('school')->where('school_type','in',$school_xingzhi)->column('id');
        }else{
			$school_id1 = Db::name('school')->column('id');
		}
        if(!empty($school_tese)){
			$school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
			$school_id2 = Db::name('school')->column('id');
		}
        if(!empty($school_xingzhi)){
			//$school_id3 = Db::name('school_xingzhi_data')->where('xingzhi_id','in',$school_xingzhi)->column('school_id');
			$school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
			$school_id3 = Db::name('school')->column('id');
		}
		$school_ids = array_intersect($school_id1,$school_id2,$school_id3);
		if(!empty($major_school_ids)){
			$school_ids = array_intersect($school_ids,$major_school_ids);
        }
		$map['id'] = ['in',$school_ids];
		
		$map['status'] = 1;
		$school_ids_ed = Db::name("school")->where($map)->column('id');
		if(!empty($school_ids_1)){
			$school_ids_1 = explode(',',$school_ids_1);
			$school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1))); 
		}
		//$school_list = Db::name("school")->where('id','in',$school_ids_ed)->column('school_uuid,id');
		//$school_uuids_ed = array_keys($school_list);
		$school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,school_type')->select();
		$school_uuids_ed = array_column($school_list,'school_uuid');
		$school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
		$school_id_ed = array_column($school_list,'id','school_uuid');
		$school_type_ed = array_column($school_list,'school_type','school_uuid');
		//dump($school_list);die;
		$school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids_ed)->field('d.school_id,t.title')->select();
		$school_tese_new = [];
		foreach($school_tese as $kt=>$vt){
			$school_tese_new[$vt['school_id']][] = $vt['title'];
			
		}
		//$school_type_ed = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id','in',$school_ids_ed)->column('d.school_id,t.title');
		$school_type_arr = Db::name('school_type')->column('id,title');
		//$school_code_ed = Db::name('school')->where('id','in',$school_ids_ed)->column('id,college_code');
		$school_code_ed = array_column($school_list,'college_code','id');
       
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$year = date('Y',strtotime("-1 year"));
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank')->where('id',$user_id)->find();
		if(empty($score_min)){
			$score_min = $member['cj_score']-30;
		}
		if(empty($score_max)){
			$score_max = $member['cj_score']+20;
		}
		if($score_min<$member['cj_score']-80){
			return $this->show(2001,"最低分".($member['cj_score']-80), '');
		}
		if($score_max>$member['cj_score']+50){
			return $this->show(2001,"最高分".($member['cj_score']+50), '');
		}
		
		/*if($member['cj_subject_mode']==1){
			if($member['cj_subjects1']=='物理'){
				$type = '物理类';
			}else{
				$type = '历史类';
			}
		}elseif($member['cj_subject_mode']==2){
			$type = '综合';
		}elseif($member['cj_subject_mode']==3){
			$type = $member['cj_subjects1'];//理科或文科
		}else{
			return $this->show(2001,"数据错误!", '');
		}*/
		$type = $member['cj_subject_mode_title'];
		
		if($batch == 1){
			$batchname = SchoolModel::getBenkeBtachs();
			$batch_score_name = '本科';
		}elseif($batch == 2){
			$batchname = SchoolModel::getZhuankeBtachs();
			$batch_score_name = '专科';
		}else{
			return $this->show(2001,"参数batch错误!", '');
		}
		
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		
		//dump($school_uuids_ed);die;
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year,'minrange'=>$score_min.','.$score_max,'type'=>$type,'batchname'=>$batchname]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		
		$list_new = [];
		$suoshu_list = SchoolModel::getSuoshuList();	
		if(!empty($list)){
			foreach($list as $k=>$v){
				if(in_array($v['SchoolUUID'],$school_uuids_ed)){
					$school_suoshu = !empty($school_suoshu_ed[$v['SchoolUUID']])?$school_suoshu_ed[$v['SchoolUUID']]:'';
					$school_id = !empty($school_id_ed[$v['SchoolUUID']])?$school_id_ed[$v['SchoolUUID']]:'';
					$school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
					//$school_type = !empty($school_type_ed[$school_id])?$school_type_ed[$school_id]:'';
					$school_type = !empty($school_type_arr[$school_type_ed[$v['SchoolUUID']]])?$school_type_arr[$school_type_ed[$v['SchoolUUID']]]:'';
					$school_code = !empty($school_code_ed[$school_id])?$school_code_ed[$school_id]:'';
			
			
					if(empty($member['cj_rank'])){
						$dengxiao_weicha = '-';
					}else{
						if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
							$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
						}else{
							$dengxiao_weicha = '-';
						}
					}
					if(empty($batch_score)){
						$linecha = '-';
					}else{
						if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
							$linecha = $v['LowestScore']-$batch_score;
						}else{
							$linecha = '-';
						}
					}
				
					$list_new[] = ['id'=>$school_id,'college_name'=>$v['CollegeName'],'school_code'=>$school_code,'school_xingzhi'=>$v['SchoolType'],'school_type'=>$school_type,'school_suoshu'=>!empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'','school_tese'=>$school_tese,'province'=>$v['Province'],'city'=>$v['SchoolInCity'],'school_uuid'=>$v['SchoolUUID'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'subject_group'=>$v['SubjectGroup']];
				}
			}
			
		}
		//dump($list_new);die;
		
		$pages = ceil($count/$pagesize);
        $data = array('list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);	
		return $this->show(1,"成功", $data);
		
    }
	
	//填报志愿-历年数据(23年 22年) 暂时废弃
    public function get_school_history_list()
    {
		$user_id = $this->user_id;
		$province_id = $this->province_id;
        $pagesize = 100;
        $page = $this->request->get("page",1,'intval'); 
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        
        $score_min = $this->request->get("score_min",0,'intval'); 
        $score_max = $this->request->get("score_max",0,'intval'); 
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim'); 
        $school_ids_1= $this->request->get("school_ids",'','trim'); 
        $cate_ids = $this->request->get("cate_ids",'','trim'); 
        $major_ids = $this->request->get("major_ids",'','trim');
		$major_ids1 = [];
		$major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
			$major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
		$major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
		$major_school_ids = [];
		if(!empty($major_ids)){
			foreach($major_ids as $km=>$vm){
				$major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
				$major_school_ids = array_merge($major_school_ids,$major_school_id);
				
			}
		}
		//dump($major_ids);die;
		
        if(!empty($province_ids)){
			$map['province_id'] = ['in',$province_ids];
        }
		if(!empty($school_type)){
			//$school_id1 = Db::name('school_type_data')->where('type_id','in',$school_type)->column('school_id');
			$school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
        }else{
			$school_id1 = Db::name('school')->column('id');
		}
        if(!empty($school_tese)){
			$school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
			$school_id2 = Db::name('school')->column('id');
		}
        if(!empty($school_xingzhi)){
			//$school_id3 = Db::name('school_xingzhi_data')->where('xingzhi_id','in',$school_xingzhi)->column('school_id');
			$school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
			$school_id3 = Db::name('school')->column('id');
		}
		$school_ids = array_intersect($school_id1,$school_id2,$school_id3);
		if(!empty($major_school_ids)){
			$school_ids = array_intersect($school_ids,$major_school_ids);
        }
		$map['id'] = ['in',$school_ids];
		
		$map['status'] = 1;
		$school_ids_ed = Db::name("school")->where($map)->column('id');
		if(!empty($school_ids_1)){
			$school_ids_1 = explode(',',$school_ids_1);
			$school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1))); 
		}
		$school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,school_type')->select();
		$school_uuids_ed = array_column($school_list,'school_uuid');
		$school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
		$school_id_ed = array_column($school_list,'id','school_uuid');
		$school_type_ed = array_column($school_list,'school_type','school_uuid');
		//dump($school_list);die;
		$school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids_ed)->field('d.school_id,t.title')->select();
		$school_tese_new = [];
		foreach($school_tese as $kt=>$vt){
			$school_tese_new[$vt['school_id']][] = $vt['title'];
			
		}
		//$school_type_ed = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id','in',$school_ids_ed)->column('d.school_id,t.title');
		$school_type_arr = Db::name('school_type')->column('id,title');
		//$school_code_ed = Db::name('school')->where('id','in',$school_ids_ed)->column('id,college_code');
		$school_code_ed = array_column($school_list,'college_code','id');
       
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank')->where('id',$user_id)->find();
		if(empty($score_min)){
			$score_min = $member['cj_score']-30;
		}
		if(empty($score_max)){
			$score_max = $member['cj_score']+20;
		}
		if($score_min<$member['cj_score']-80){
			return $this->show(2001,"最低分".($member['cj_score']-80), '');
		}
		if($score_max>$member['cj_score']+50){
			return $this->show(2001,"最高分".($member['cj_score']+50), '');
		}
		$type = $member['cj_subject_mode_title'];
		
		if($batch == 1){
			$batchname = SchoolModel::getBenkeBtachs();
			$batch_score_name = '本科';
		}elseif($batch == 2){
			$batchname = SchoolModel::getZhuankeBtachs();
			$batch_score_name = '专科';
		}else{
			return $this->show(2001,"参数batch错误!", '');
		}
		
		//23年数据
		$year = date('Y',strtotime("-2 year"));
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year,'minrange'=>$score_min.','.$score_max,'type'=>$type,'batchname'=>$batchname]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		
		$list_new_1 = [];
		$suoshu_list = SchoolModel::getSuoshuList();	
		if(!empty($list)){
			foreach($list as $k=>$v){
				if(in_array($v['SchoolUUID'],$school_uuids_ed)){
					$school_suoshu = !empty($school_suoshu_ed[$v['SchoolUUID']])?$school_suoshu_ed[$v['SchoolUUID']]:'';
					$school_id = !empty($school_id_ed[$v['SchoolUUID']])?$school_id_ed[$v['SchoolUUID']]:'';
					$school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
					//$school_type = !empty($school_type_ed[$school_id])?$school_type_ed[$school_id]:'';
					$school_type = !empty($school_type_arr[$school_type_ed[$v['SchoolUUID']]])?$school_type_arr[$school_type_ed[$v['SchoolUUID']]]:'';
					$school_code = !empty($school_code_ed[$school_id])?$school_code_ed[$school_id]:'';
			
			
					if(empty($member['cj_rank'])){
						$dengxiao_weicha = '-';
					}else{
						if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
							$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
						}else{
							$dengxiao_weicha = '-';
						}
					}
					if(empty($batch_score)){
						$linecha = '-';
					}else{
						if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
							$linecha = $v['LowestScore']-$batch_score;
						}else{
							$linecha = '-';
						}
					}
				
					$list_new_1[] = ['id'=>$school_id,'college_name'=>$v['CollegeName'],'school_code'=>$school_code,'school_xingzhi'=>$v['SchoolType'],'school_type'=>$school_type,'school_suoshu'=>!empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'','school_tese'=>$school_tese,'province'=>$v['Province'],'city'=>$v['SchoolInCity'],'school_uuid'=>$v['SchoolUUID'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'subject_group'=>$v['SubjectGroup']];
				}
			}
			
		}
		$pages = ceil($count/$pagesize);
        $data_1 = array('list'=>$list_new_1,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);	
		//dump($list_new_1);die;
		
		//22年数据
		$year = date('Y',strtotime("-3 year"));
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year,'minrange'=>$score_min.','.$score_max,'type'=>$type,'batchname'=>$batchname]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		
		$list_new_2 = [];
		$suoshu_list = SchoolModel::getSuoshuList();	
		if(!empty($list)){
			foreach($list as $k=>$v){
				if(in_array($v['SchoolUUID'],$school_uuids_ed)){
					$school_suoshu = !empty($school_suoshu_ed[$v['SchoolUUID']])?$school_suoshu_ed[$v['SchoolUUID']]:'';
					$school_id = !empty($school_id_ed[$v['SchoolUUID']])?$school_id_ed[$v['SchoolUUID']]:'';
					$school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
					//$school_type = !empty($school_type_ed[$school_id])?$school_type_ed[$school_id]:'';
					$school_type = !empty($school_type_arr[$school_type_ed[$v['SchoolUUID']]])?$school_type_arr[$school_type_ed[$v['SchoolUUID']]]:'';
					$school_code = !empty($school_code_ed[$school_id])?$school_code_ed[$school_id]:'';
			
			
					if(empty($member['cj_rank'])){
						$dengxiao_weicha = '-';
					}else{
						if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
							$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
						}else{
							$dengxiao_weicha = '-';
						}
					}
					if(empty($batch_score)){
						$linecha = '-';
					}else{
						if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
							$linecha = $v['LowestScore']-$batch_score;
						}else{
							$linecha = '-';
						}
					}
				
					$list_new_2[] = ['id'=>$school_id,'college_name'=>$v['CollegeName'],'school_code'=>$school_code,'school_xingzhi'=>$v['SchoolType'],'school_type'=>$school_type,'school_suoshu'=>!empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'','school_tese'=>$school_tese,'province'=>$v['Province'],'city'=>$v['SchoolInCity'],'school_uuid'=>$v['SchoolUUID'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'subject_group'=>$v['SubjectGroup']];
				}
			}
			
		}
		$pages = ceil($count/$pagesize);
        $data_2= array('list'=>$list_new_2,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);	
		return $this->show(1,"成功", ['history_data1'=>$data_1,'history_data2'=>$data_2]);
		
    }
	
	//填报志愿-历年数据(23年 22年)-根据院校名称获取历年数据
    public function get_school_history_info()
    {
		$user_id = $this->user_id;
		$province_id = $this->province_id;
        $pagesize = 1;
        $page = 1; 
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        $schooluuid= $this->request->get("school_uuid",'','trim');
        if(empty($schooluuid)){
            return $this->show(2001,"缺少参数schooluuid!", '');
        }
        
        
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank')->where('id',$user_id)->find();
		$type = $member['cj_subject_mode_title'];
		if($batch == 1){
			$batchname = SchoolModel::getBenkeBtachs();
			$batch_score_name = '本科';
		}elseif($batch == 2){
			$batchname = SchoolModel::getZhuankeBtachs();
			$batch_score_name = '专科';
		}else{
			return $this->show(2001,"参数batch错误!", '');
		}
		
		//23年数据
		$year1 = date('Y',strtotime("-2 year"));
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year1)->value('socre');//批次分数
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year1,'type'=>$type,'batchname'=>$batchname,'schooluuid'=>$schooluuid]);
		if($result[0] != 200){
            $list = [];
		}else{
			$list = $result[1][1];
		}
		$list_new_1 = [];
		if(!empty($list)){
			foreach($list as $k=>$v){
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
						$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
				$list_new_1[] = ['school_uuid'=>$v['SchoolUUID'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha];
			}	
		}
		
		//22年数据
		$year2 = date('Y',strtotime("-3 year"));
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year2)->value('socre');//批次分数
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year2,'type'=>$type,'batchname'=>$batchname,'schooluuid'=>$schooluuid]);
		if($result[0] != 200){
            $list = [];
		}else{
			$list = $result[1][1];
		}
		$list_new_2 = [];
		if(!empty($list)){
			foreach($list as $k=>$v){
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
						$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
			
				$list_new_2[] = ['school_uuid'=>$v['SchoolUUID'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'subject_group'=>$v['SubjectGroup']];
			}
			
		}
		return $this->show(1,"成功", ['history_years'=>[$year1,$year2],'history_data1'=>$list_new_1,'history_data2'=>$list_new_2]);
		
    }
	
	//填报志愿-获取专业
    public function get_major_list()
    {
		$user_id = $this->user_id;
		$province_id = $this->province_id;
       
        $school_uuid= $this->request->get("school_uuid",'','trim');
        if(empty($school_uuid)){
            return $this->show(2001,"缺少参数school_uuid!", '');
        }
        $school_name= $this->request->get("school_name",'','trim');
        if(empty($school_name)){
            return $this->show(2001,"缺少参数school_name!", '');
        }
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        $score_min = $this->request->get("score_min",0,'intval'); 
        $score_max = $this->request->get("score_max",0,'intval'); 
		
		$cate_ids = $this->request->get("cate_ids",'','trim'); 
		$major_ids1 = [];
        if(!empty($cate_ids)){
			$major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
        $major_ids = $this->request->get("major_ids",'','trim');
		$major_ids = explode(',',$major_ids);
		$major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
		$major_titles = [];
        if(!empty($major_ids)){
			$major_titles = Db::name("major")->where('cate_level',3)->where('id','in',$major_ids)->column('cate_title');
        }
		
		
		
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank')->where('id',$user_id)->find();
		if(empty($score_min)){
			$score_min = $member['cj_score']-30;
		}
		if(empty($score_max)){
			$score_max = $member['cj_score']+20;
		}
		if($score_min<$member['cj_score']-80){
			return $this->show(2001,"最低分".($member['cj_score']-80), '');
		}
		if($score_max>$member['cj_score']+50){
			return $this->show(2001,"最高分".($member['cj_score']+50), '');
		}
		/*if($member['cj_subject_mode']==1){
			if($member['cj_subjects1']=='物理'){
				$type = '物理类';
			}else{
				$type = '历史类';
			}
		}elseif($member['cj_subject_mode']==3){
			$type = '综合';
		}elseif($member['cj_subject_mode']==3){
			$type = $member['cj_subjects1'];//理科或文科
		}else{
			return $this->show(2001,"数据错误!", '');
		}*/
		$type = $member['cj_subject_mode_title'];
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		
		if($batch == 1){
			$batchname = SchoolModel::getBenkeBtachs();
			$batch_score_name = '本科';
		}elseif($batch == 2){
			$batchname = SchoolModel::getZhuankeBtachs();
			$batch_score_name = '专科';
		}else{
			return $this->show(2001,"参数batch错误!", '');
		}
		
		//23年数据
		$year = date('Y',strtotime("-2 year"));
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schooluuid'=>$school_uuid,'year'=>$year,'minrange'=>$score_min.','.$score_max,'typename'=>$type,'batchname'=>$batchname]);
		//dump($result);die;
		if($result[0] != 200){
            $list = [];
		}else{
			$list = $result[1][1];
		}
		$list_new_1 = [];
		//dump($list);die;
		if(!empty($list)){
			$list = array_unique_two($list);//专业去重
			//获取院校的全部专业的招生计划
			$result_plan = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>100,'year'=>$year,'type'=>$type,'provincename'=>$enrollprovince,'schoolname'=>$school_name]);
			if($result_plan[0] != 200){
				return $this->show(2002,$result_plan[1]??'error', '');
			}
			$list_plan = $result_plan[1][1];
			$list_plan_number = array_column($list_plan,'EnrollmentNumbers','CollegeMajorName');//整理好专业和招生人数，方便下面模糊匹配
		
			foreach($list as $k=>$v){
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestSection']) && is_numeric($v['LowestSection'])){
						$dengxiao_weicha = $v['LowestSection']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
				
				$list_new_1[$k] = ['major_name'=>$v['MajorName'],'major_code'=>$v['MajorCode'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestSection'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'major_code_standard'=>$v['MajorStandardCode'],'plan_nums'=>search_plan_like($list_plan_number,$v['MajorName'])];
			}
		}
		
		//22年数据
		$year = date('Y',strtotime("-3 year"));
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schooluuid'=>$school_uuid,'year'=>$year,'minrange'=>$score_min.','.$score_max,'typename'=>$type,'batchname'=>$batchname]);
		if($result[0] != 200){
            $list = [];
		}else{
			$list = $result[1][1];
		}
		$list_new_2 = [];
		//dump($list);die;
		if(!empty($list)){
			$list = array_unique_two($list);//专业去重
			//获取院校的全部专业的招生计划
			$result_plan = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>100,'year'=>$year,'type'=>$type,'provincename'=>$enrollprovince,'schoolname'=>$school_name]);
			if($result_plan[0] != 200){
				return $this->show(2002,$result_plan[1]??'error', '');
			}
			$list_plan = $result_plan[1][1];
			$list_plan_number = array_column($list_plan,'EnrollmentNumbers','CollegeMajorName');//整理好专业和招生人数，方便下面模糊匹配
		
			foreach($list as $k=>$v){
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestSection']) && is_numeric($v['LowestSection'])){
						$dengxiao_weicha = $v['LowestSection']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
				
				$list_new_2[$k] = ['major_name'=>$v['MajorName'],'major_code'=>$v['MajorCode'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestSection'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'major_code_standard'=>$v['MajorStandardCode'],'plan_nums'=>search_plan_like($list_plan_number,$v['MajorName'])];
			}
		}
		
		//去年数据
		$year = date('Y',strtotime("-1 year"));
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schooluuid'=>$school_uuid,'year'=>$year,'minrange'=>$score_min.','.$score_max,'typename'=>$type,'batchname'=>$batchname]);
		//dump($result);die;
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$list_new = [];
		//dump($list);die;
		if(!empty($list)){
			$list = array_unique_two($list);//专业去重
			//获取院校的全部专业的招生计划
			$result_plan = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>100,'year'=>$year,'type'=>$type,'provincename'=>$enrollprovince,'schoolname'=>$school_name]);
			if($result_plan[0] != 200){
				return $this->show(2002,$result_plan[1]??'error', '');
			}
			$list_plan = $result_plan[1][1];
			$list_plan_number = array_column($list_plan,'EnrollmentNumbers','CollegeMajorName');//整理好专业和招生人数，方便下面模糊匹配
		
			foreach($list as $k=>$v){
				if(!empty($major_titles)){
					if(!in_array($v['MajorName'],$major_titles)){
						continue;
					}
				}
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestSection']) && is_numeric($v['LowestSection'])){
						$dengxiao_weicha = $v['LowestSection']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
				
				$marjor_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
				foreach($list_new_1 as $kl=>$vl){
					if($v['MajorName'] == $vl['major_name']){
						$marjor_new_1 = $vl;
						break;
					}
				}
				$marjor_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
				foreach($list_new_2 as $k2=>$v2){
					if($v['MajorName'] == $v2['major_name']){
						$marjor_new_2 = $v2;
						break;
					}
				}
				
				$list_new[$k] = ['major_name'=>$v['MajorName'],'major_code'=>$v['MajorCode'],'major_code_standard'=>$v['MajorStandardCode'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestSection'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'plan_nums'=>search_plan_like($list_plan_number,$v['MajorName'])
				,'score_min_1'=>$marjor_new_1['score_min']??'-','weici_min_1'=>$marjor_new_1['weici_min']??'-','dengxiao_weicha_1'=>$marjor_new_1['dengxiao_weicha']??'-','linecha_1'=>$marjor_new_1['linecha']??'-','plan_nums_1'=>$marjor_new_1['plan_nums']??'-'
				,'score_min_2'=>$marjor_new_2['score_min']??'-','weici_min_2'=>$marjor_new_2['weici_min']??'-','dengxiao_weicha_2'=>$marjor_new_2['dengxiao_weicha']??'-','linecha_2'=>$marjor_new_2['dengxiao_weicha']??'-','plan_nums_2'=>$marjor_new_2['plan_nums']??'-'];
			}
		}
		//dump($list_new);die;
		
		return $this->show(1,"成功", $list_new);
		
    }
	
	
    //保存方案
    public function save_zhiyuan(){
        $user_id = $this->user_id;
        $province_id = $this->province_id;
        if($this->request->isPost()){
			
			/*$data['zhiyuan'] = $this->request->post("zhiyuan",'','trim');
			$zhiyuan = json_decode($data['zhiyuan'],true);
			if(empty($zhiyuan) || !is_array($zhiyuan)){
				return $this->show(2001,"请选择正确的专业!", '');
			}*/
			$data['zhiyuan_json'] = $this->request->post("zhiyuan_json",'','trim');//志愿全部数据
			$zhiyuan_json = json_decode($data['zhiyuan_json'],true);
			if(empty($zhiyuan_json) || !is_array($zhiyuan_json)){
				return $this->show(2001,"请选择专业!", '');
			}
			$data['batch'] = $this->request->post("batch",1,'intval');
			$data['type'] = $this->request->post("type",1,'intval');
			if(!in_array($data['type'],[1,2]) || !in_array($data['batch'],[1,2])){
				return $this->show(2001,"type或batch参数不正确!", '');
			}
			$data['score_min'] = $this->request->post("score_min",0,'intval'); 
			$data['score_max'] = $this->request->post("score_max",0,'intval'); 
			$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title')->where('id',$user_id)->find();
			if($data['score_min']< ($member['cj_score']-80)){
				return $this->show(2001,"最低分".($member['cj_score']-80), '');
			}
			if($data['score_max']>($member['cj_score']+50)){
				return $this->show(2001,"最高分".($member['cj_score']+50), '');
			}
			
			/*
			if($member['cj_subject_mode']==1){
				if($member['cj_subjects1']=='物理'){
					$typename = '物理类';
				}else{
					$typename = '历史类';
				}
			}else{
				$typename = '综合';
			}*/  
			$typename = $member['cj_subject_mode_title'];         
			$data['typename'] = $typename;
			
			 
			$data['cj_subjects'] = $member['cj_subjects'];                
			$data['cj_score'] = $member['cj_score'];
			$data['create_time'] = time();
			$data['update_time'] = time();
			$data['user_id'] = $user_id;
			$data['province_id'] = $province_id;
			$xuhao = Db::name("member_zhiyuan")->where('user_id',$user_id)->order('id desc')->value('xuhao');
			$data['xuhao'] = $xuhao+1;
			$data['title'] = '志愿表'.$data['xuhao'];
			$data['user_id'] = $user_id;
			$res = Db::name("member_zhiyuan")->insert($data);
			if( $res !== false ){
				return $this->show(1,"success", '');
			}else{
				return $this->show(2002, "fail", "");
			} 
		}else{
            return $this->show(2001, "非法请求", "");
        }
    }
	
	//根据院校专业查询招生人数
	public function get_plan_nums()
    {
		$user_id = $this->user_id;
		$province_id = $this->province_id;
       
        //$school_uuid= $this->request->get("school_uuid",'','trim');
        //if(empty($school_uuid)){
        //   return $this->show(2001,"缺少参数school_uuid!", '');
        //}
        $major_name= $this->request->get("major_name",'','trim');
        if(empty($major_name)){
           return $this->show(2001,"缺少参数major_name!", '');
        }
        $school_name = $this->request->get("school_name",'','trim');
        if(empty($school_name)){
            return $this->show(2001,"缺少参数school_name!", '');
        }
		
		$year = date('Y',strtotime("-1 year"));
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title')->where('id',$user_id)->find();
		$type = $member['cj_subject_mode_title'];
		$provincename = Db::name("area")->where('id',$province_id)->value('name');
		$result = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>100,'year'=>$year,'type'=>$type,'provincename'=>$provincename,'schoolname'=>$school_name,'collegemajorname'=>$major_name]);
		//dump($result);die;
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];//dump($list);
		
		
		$nums = isset($list[0]['EnrollmentNumbers'])?$list[0]['EnrollmentNumbers']:'-';
		return $this->show(1,"success", ['nums'=>$nums]);
	}
	
	
	
	//填报志愿
    public function get_school_list_new()
    {
		
		//$start_time = microtime(true);//计时
		
		set_time_limit(0); 
		$user_id = $this->user_id;
		$province_id = $this->province_id;
        $pagesize = 10; 
        $page = $this->request->get("page",1,'intval'); //$page = 1;
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        
        $score_min = $this->request->get("score_min",0,'intval'); 
        $score_max = $this->request->get("score_max",0,'intval'); 
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim'); 
        $school_ids_1= $this->request->get("school_ids",'','trim'); 
        $cate_ids = $this->request->get("cate_ids",'','trim'); 
        $major_ids = $this->request->get("major_ids",'','trim');
		$major_ids1 = [];
		$major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
			$major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
		$major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
		$major_school_ids = [];
		if(!empty($major_ids)){
			foreach($major_ids as $km=>$vm){
				$major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
				$major_school_ids = array_merge($major_school_ids,$major_school_id);
				
			}
		}
        if(!empty($province_ids)){
			$map['province_id'] = ['in',$province_ids];
        }
		$school_id_all = Db::name('school')->column('id');
		if(!empty($school_type)){
			//$school_id1 = Db::name('school_type_data')->where('type_id','in',$school_type)->column('school_id');
			$school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
        }else{
			$school_id1 = $school_id_all;
		}
        if(!empty($school_tese)){
			$school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
			$school_id2 = $school_id_all;
		}
        if(!empty($school_xingzhi)){
			//$school_id3 = Db::name('school_xingzhi_data')->where('xingzhi_id','in',$school_xingzhi)->column('school_id');
			$school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
			$school_id3 = $school_id_all;
		}
		$school_ids = array_intersect($school_id1,$school_id2,$school_id3);
		if(!empty($major_school_ids)){
			$school_ids = array_intersect($school_ids,$major_school_ids);
        }
		$map['id'] = ['in',$school_ids];
		$map['status'] = 1;
		$school_ids_ed = Db::name("school")->where($map)->column('id');
		if(!empty($school_ids_1)){
			$school_ids_1 = explode(',',$school_ids_1);
			$school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1))); 
		}
		//$school_list = Db::name("school")->where('id','in',$school_ids_ed)->column('school_uuid,id');
		//$school_uuids_ed = array_keys($school_list);
		$school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,ranking,school_type')->select();
		$school_uuids_ed = array_column($school_list,'school_uuid');
		$school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
		$school_id_ed = array_column($school_list,'id','school_uuid');
		$school_code_ed = array_column($school_list,'college_code','id');
		$school_rank_ed = array_column($school_list,'ranking','id');
		$school_type_ed = array_column($school_list,'school_type','school_uuid');
		//dump($school_list);die;
		$school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids_ed)->field('d.school_id,t.title')->select();
		$school_tese_new = [];
		foreach($school_tese as $kt=>$vt){
			$school_tese_new[$vt['school_id']][] = $vt['title'];
			
		}
		//$school_type_ed = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id','in',$school_ids_ed)->column('d.school_id,t.title');
		$school_type_arr = Db::name('school_type')->column('id,title');
       
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$year = date('Y',strtotime("-1 year"));
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank')->where('id',$user_id)->find();
		if(empty($score_min)){
			$score_min = $member['cj_score']-30;
		}
		if(empty($score_max)){
			$score_max = $member['cj_score']+20;
		}
		if($score_min<$member['cj_score']-80){
			return $this->show(2001,"最低分".($member['cj_score']-80), '');
		}
		if($score_max>$member['cj_score']+50){
			return $this->show(2001,"最高分".($member['cj_score']+50), '');
		}
		$type = $member['cj_subject_mode_title'];
		if($batch == 1){
			$batchname = SchoolModel::getBenkeBtachs();
			$batch_score_name = '本科';
		}elseif($batch == 2){
			$batchname = SchoolModel::getZhuankeBtachs();
			$batch_score_name = '专科';
		}else{
			return $this->show(2001,"参数batch错误!", '');
		}
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		//dump($school_uuids_ed);die;
		//去年院校数据
		$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>$pagesize,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year,'minrange'=>$score_min.','.$score_max,'type'=>$type,'batchname'=>$batchname]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		//$count = count($list);
		
		$year1 = date('Y',strtotime("-2 year"));
		$year2 = date('Y',strtotime("-3 year"));
		$batch_score1 = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year1)->value('socre');//批次分数
		$batch_score2 = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year2)->value('socre');//批次分数
		

		
		//23年院校数据
		$result_1 = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>50,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year1,'minrange'=>$score_min.','.$score_max,'type'=>$type,'batchname'=>$batchname]);
		if($result_1[0] != 200){
            $list_1 = [];
		}else{
			$list_1 = $result_1[1][1];
		}
		$list_school_1 = [];
		if(!empty($list_1)){
			foreach($list_1 as $k=>$v){
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
						$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
				$list_school_1[] = ['school_uuid'=>$v['SchoolUUID'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'subject_group'=>$v['SubjectGroup']];
			}	
		}
		//22年院校数据
		$result_2 = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>50,'searchtype'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year2,'minrange'=>$score_min.','.$score_max,'type'=>$type,'batchname'=>$batchname]);
		if($result_2[0] != 200){
            $list_2 = [];
		}else{
			$list_2 = $result_2[1][1];
		}
		$list_school_2 = [];
		if(!empty($list_2)){
			foreach($list_2 as $k=>$v){
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
						$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
				$list_school_2[] = ['school_uuid'=>$v['SchoolUUID'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'subject_group'=>$v['SubjectGroup']];
			}	
		}
		
		
		$list_new = [];
		$suoshu_list = SchoolModel::getSuoshuList();	
		if(!empty($list)){
			foreach($list as $k=>$v){
				if(in_array($v['SchoolUUID'],$school_uuids_ed)){
					$school_suoshu = !empty($school_suoshu_ed[$v['SchoolUUID']])?$school_suoshu_ed[$v['SchoolUUID']]:'';
					$school_id = !empty($school_id_ed[$v['SchoolUUID']])?$school_id_ed[$v['SchoolUUID']]:'';
					$school_tese = !empty($school_tese_new[$school_id])?$school_tese_new[$school_id]:'';
					//$school_type = !empty($school_type_ed[$school_id])?$school_type_ed[$school_id]:'';
					$school_type = !empty($school_type_arr[$school_type_ed[$v['SchoolUUID']]])?$school_type_arr[$school_type_ed[$v['SchoolUUID']]]:'';
					$school_code = !empty($school_code_ed[$school_id])?$school_code_ed[$school_id]:'';
					$school_rank = !empty($school_rank_ed[$school_id])?$school_rank_ed[$school_id]:'';
			
					
					//获取去年专业数据
					$result_major = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>15,'enrollprovince'=>$enrollprovince,'schooluuid'=>$v['SchoolUUID'],'year'=>$year,'minrange'=>$score_min.','.$score_max,'typename'=>$type,'batchname'=>$batchname]);
					//dump($result_major);die;
					if($result_major[0] != 200){
						return $this->show(2002,$result_major[1]??'error', '');
					}
					$list_major = $result_major[1][1];
					if(!empty($list_major)){
						$list_major = array_unique_two($list_major);//专业去重
						
						//23年专业数据
						$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schooluuid'=>$v['SchoolUUID'],'year'=>$year1,'minrange'=>$score_min.','.$score_max,'typename'=>$type,'batchname'=>$batchname]);
						//dump($result);die;
						if($result[0] != 200){
							$list_1 = [];
						}else{
							$list_1 = $result[1][1];
						}
						$list_new_1 = [];
						if(!empty($list_1)){
							//$list_1 = array_unique_two($list_1);//专业去重
							//获取院校下的23年专业的招生计划
							$result_plan = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>100,'year'=>$year1,'type'=>$type,'provincename'=>$enrollprovince,'schoolname'=>$v['CollegeName']]);
							if($result_plan[0] != 200){
								return $this->show(2002,$result_plan[1]??'error', '');
							}
							$list_plan = $result_plan[1][1];
							$list_plan_number = array_column($list_plan,'EnrollmentNumbers','CollegeMajorName');//整理好专业和招生人数，方便下面模糊匹配
							foreach($list_1 as $k_1=>$v_1){
								if(empty($member['cj_rank'])){
									$dengxiao_weicha = '-';
								}else{
									if(!empty($v_1['LowestSection']) && is_numeric($v_1['LowestSection'])){
										$dengxiao_weicha = $v_1['LowestSection']-$member['cj_rank'];
									}else{
										$dengxiao_weicha = '-';
									}
								}
								if(empty($batch_score1)){
									$linecha = '-';
								}else{
									if(!empty($v_1['LowestScore']) && is_numeric($v_1['LowestScore'])){
										$linecha = $v_1['LowestScore']-$batch_score1;
									}else{
										$linecha = '-';
									}
								}
								$list_new_1[$k_1] = ['major_name'=>$v_1['MajorName'],'major_code'=>$v_1['MajorCode'],'score_min'=>$v_1['LowestScore'],'weici_min'=>$v_1['LowestSection'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'major_code_standard'=>$v_1['MajorStandardCode'],'plan_nums'=>search_plan_like($list_plan_number,$v_1['MajorName'])];
							}
						}
						
						//22年专业数据
						$result = GuguService::make('/metadata/ceemajorline',['appkey'=>'TZK6DJZ5LVS6V8LYDAS9WE3K4TM8ZQWZ','pageindex'=>1,'pagesize'=>100,'enrollprovince'=>$enrollprovince,'schooluuid'=>$v['SchoolUUID'],'year'=>$year2,'minrange'=>$score_min.','.$score_max,'typename'=>$type,'batchname'=>$batchname]);
						if($result[0] != 200){
							$list_2 = [];
						}else{
							$list_2 = $result[1][1];
						}
						$list_new_2 = [];
						//dump($list);die;
						if(!empty($list_2)){
							//$list_2 = array_unique_two($list_2);//专业去重
							//获取院校下的22年专业的招生计划
							$result_plan = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>100,'year'=>$year2,'type'=>$type,'provincename'=>$enrollprovince,'schoolname'=>$v['CollegeName']]);
							if($result_plan[0] != 200){
								return $this->show(2002,$result_plan[1]??'error', '');
							}
							$list_plan = $result_plan[1][1];
							$list_plan_number = array_column($list_plan,'EnrollmentNumbers','CollegeMajorName');//整理好专业和招生人数，方便下面模糊匹配
							foreach($list_2 as $k_2=>$v_2){
								if(empty($member['cj_rank'])){
									$dengxiao_weicha = '-';
								}else{
									if(!empty($v_2['LowestSection']) && is_numeric($v_2['LowestSection'])){
										$dengxiao_weicha = $v_2['LowestSection']-$member['cj_rank'];
									}else{
										$dengxiao_weicha = '-';
									}
								}
								if(empty($batch_score2)){
									$linecha = '-';
								}else{
									if(!empty($v_2['LowestScore']) && is_numeric($v_2['LowestScore'])){
										$linecha = $v_2['LowestScore']-$batch_score2;
									}else{
										$linecha = '-';
									}
								}
								$list_new_2[$k_2] = ['major_name'=>$v_2['MajorName'],'major_code'=>$v_2['MajorCode'],'score_min'=>$v_2['LowestScore'],'weici_min'=>$v_2['LowestSection'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'major_code_standard'=>$v_2['MajorStandardCode'],'plan_nums'=>search_plan_like($list_plan_number,$v_2['MajorName'])];
							}
						}
			
						//获取院校下的去年专业的招生计划
						$result_plan = GuguService::make('/metadata/college-enrollment-plan',['appkey'=>'4PRZZRKKA2QXJNHUF3222XWKCNTW7UYC','pageindex'=>1,'pagesize'=>100,'year'=>$year,'type'=>$type,'provincename'=>$enrollprovince,'schoolname'=>$v['CollegeName']]);
						if($result_plan[0] != 200){
							return $this->show(2002,$result_plan[1]??'error', '');
						}
						$list_plan = $result_plan[1][1];
						$list_plan_number = array_column($list_plan,'EnrollmentNumbers','CollegeMajorName');//整理好专业和招生人数，方便下面模糊匹配
						
						$list_new_major = [];
						foreach($list_major as $km=>$vm){
							if(empty($member['cj_rank'])){
								$dengxiao_weicha = '-';
							}else{
								if(!empty($vm['LowestSection']) && is_numeric($vm['LowestSection'])){
									$dengxiao_weicha = $vm['LowestSection']-$member['cj_rank'];
								}else{
									$dengxiao_weicha = '-';
								}
							}
							if(empty($batch_score)){
								$linecha = '-';
							}else{
								if(!empty($vm['LowestScore']) && is_numeric($vm['LowestScore'])){
									$linecha = $vm['LowestScore']-$batch_score;
								}else{
									$linecha = '-';
								}
							}
							$marjor_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
							foreach($list_new_1 as $vnl){
								if($vm['MajorName'] == $vnl['major_name']){
									$marjor_new_1 = $vnl;
									break;
								}
							}
							$marjor_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
							foreach($list_new_2 as $vn2){
								if($vm['MajorName'] == $vn2['major_name']){
									$marjor_new_2 = $vn2;
									break;
								}
							}
							
							$list_new_major[$km] = ['major_name'=>$vm['MajorName'],'major_code'=>$vm['MajorCode'],'score_min'=>$vm['LowestScore'],'weici_min'=>$vm['LowestSection'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,'major_code_standard'=>$vm['MajorStandardCode'],'plan_nums'=>search_plan_like($list_plan_number,$vm['MajorName']),
							'score_min_1'=>$marjor_new_1['score_min']??'-','weici_min_1'=>$marjor_new_1['weici_min']??'-','dengxiao_weicha_1'=>$marjor_new_1['dengxiao_weicha']??'-','linecha_1'=>$marjor_new_1['linecha']??'-','plan_nums_1'=>$marjor_new_1['plan_nums']??'-',
							'score_min_2'=>$marjor_new_2['score_min']??'-','weici_min_2'=>$marjor_new_2['weici_min']??'-','dengxiao_weicha_2'=>$marjor_new_2['dengxiao_weicha']??'-','linecha_2'=>$marjor_new_2['linecha']??'-','plan_nums_2'=>$marjor_new_2['plan_nums']??'-'];
						}
						
						if(empty($member['cj_rank'])){
							$dengxiao_weicha = '-';
						}else{
							if(!empty($v['LowestRank']) && is_numeric($v['LowestRank'])){
								$dengxiao_weicha = $v['LowestRank']-$member['cj_rank'];
							}else{
								$dengxiao_weicha = '-';
							}
						}
						
						if(empty($batch_score)){
							$linecha = '-';
						}else{
							if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
								$linecha = $v['LowestScore']-$batch_score;
							}else{
								$linecha = '-';
							}
						}
						$school_new_1 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
						foreach($list_school_1 as $vsl){
							if($v['SchoolUUID'] == $vsl['school_uuid'] && $v['SubjectGroup'] == $vsl['subject_group']){
								$school_new_1 = $vsl;
								break;
							}
						}
						$school_new_2 = ['score_min'=>'-','weici_min'=>'-','dengxiao_weicha'=>'-','linecha'=>'-','plan_nums'=>'-'];
						foreach($list_school_2 as $vs2){
							if($v['SchoolUUID'] == $vs2['school_uuid'] && $v['SubjectGroup'] == $vs2['subject_group']){
								$school_new_2 = $vs2;
								break;
							}
						}
						
						$list_new[] = ['college_name'=>$v['CollegeName'],'school_code'=>$school_code,'rank'=>$school_rank,'school_xingzhi'=>$v['SchoolType'],'school_type'=>$school_type,'school_suoshu'=>!empty($suoshu_list[$school_suoshu])?$suoshu_list[$school_suoshu]:'','school_tese'=>$school_tese,'province'=>$v['Province'],'city'=>$v['SchoolInCity'],'school_uuid'=>$v['SchoolUUID'],'subject_group'=>$v['SubjectGroup'],'score_min'=>$v['LowestScore'],'weici_min'=>$v['LowestRank'],'dengxiao_weicha'=>$dengxiao_weicha,'linecha'=>$linecha,
						'score_min_1'=>$school_new_1['score_min']??'-','weici_min_1'=>$school_new_1['weici_min']??'-','dengxiao_weicha_1'=>$school_new_1['dengxiao_weicha']??'-','linecha_1'=>$school_new_1['linecha']??'-','plan_nums_1'=>$school_new_1['plan_nums']??'-',
						'score_min_2'=>$school_new_2['score_min']??'-','weici_min_2'=>$school_new_2['weici_min']??'-','dengxiao_weicha_2'=>$school_new_2['dengxiao_weicha']??'-','linecha_2'=>$school_new_2['linecha']??'-','plan_nums_2'=>$school_new_2['plan_nums']??'-',
						'major_list'=>$list_new_major];//,'risk_level'=>'较高风险','risk_title'=>'冲'
						//dump($list_new);
						//$end_time = microtime(true);//计时
						//echo "执行时间: " . ($end_time - $start_time) . " 秒";die;
					}
					
				}
			}
			
		}
		$count_real = count($list_new);//过滤后真实数量
		
		
		//dump($list_new);die;
		
		$pages = ceil($count/$pagesize);
		if($pages == 1){
			$count = $count_real;
		}
        $data = array('list'=>$list_new,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);	
		return $this->show(1,"成功", $data);
		
    }
	//填报志愿
    public function get_school_list_final()
    {
		
		//$start_time = microtime(true);//计时
		
		set_time_limit(0); 
		$user_id = $this->user_id;
		$province_id = $this->province_id;
        $pagesize = 10; 
        $page = $this->request->get("page",1,'intval'); //$page = 1;
        $batch= $this->request->get("batch",1,'intval');
        if(empty($batch)){
            return $this->show(2001,"缺少参数batch!", '');
        }
        
        $score_min = $this->request->get("score_min",0,'intval'); 
        $score_max = $this->request->get("score_max",0,'intval'); 
        $province_ids= $this->request->get("province_ids",'','trim');
        $school_type= $this->request->get("school_type",'','trim');
        $school_tese= $this->request->get("school_tese",'','trim');
        $school_xingzhi= $this->request->get("school_xingzhi",'','trim'); 
        $school_ids_1= $this->request->get("school_ids",'','trim'); 
        $cate_ids = $this->request->get("cate_ids",'','trim'); 
        $major_ids = $this->request->get("major_ids",'','trim');
		$major_ids1 = [];
		$major_ids = explode(',',$major_ids);
        if(!empty($cate_ids)){
			$major_ids1 = Db::name("major")->where('cate_level',3)->where('cate_pid','in',$cate_ids)->column('id');
        }
		$major_ids = array_filter(array_unique(array_merge($major_ids,$major_ids1)));
		$major_school_ids = [];
		if(!empty($major_ids)){
			foreach($major_ids as $km=>$vm){
				$major_school_id = Db::name('school_major_data')->where('FIND_IN_SET(:id,major_ids)',['id' => $vm])->column('school_id');
				$major_school_ids = array_merge($major_school_ids,$major_school_id);
				
			}
		}
        if(!empty($province_ids)){
			$map['province_id'] = ['in',$province_ids];
        }
		$school_id_all = Db::name('school')->column('id');
		if(!empty($school_type)){
			//$school_id1 = Db::name('school_type_data')->where('type_id','in',$school_type)->column('school_id');
			$school_id1 = Db::name('school')->where('school_type','in',$school_type)->column('id');
        }else{
			$school_id1 = $school_id_all;
		}
        if(!empty($school_tese)){
			$school_id2 = Db::name('school_tese_data')->where('tese_id','in',$school_tese)->column('school_id');
        }else{
			$school_id2 = $school_id_all;
		}
        if(!empty($school_xingzhi)){
			//$school_id3 = Db::name('school_xingzhi_data')->where('xingzhi_id','in',$school_xingzhi)->column('school_id');
			$school_id3 = Db::name('school')->where('school_xingzhi','in',$school_xingzhi)->column('id');
        }else{
			$school_id3 = $school_id_all;
		}
		$school_ids = array_intersect($school_id1,$school_id2,$school_id3);
		if(!empty($major_school_ids)){
			$school_ids = array_intersect($school_ids,$major_school_ids);
        }
		$map['id'] = ['in',$school_ids];
		$map['status'] = 1;
		$school_ids_ed = Db::name("school")->where($map)->column('id');
		if(!empty($school_ids_1)){
			$school_ids_1 = explode(',',$school_ids_1);
			$school_ids_ed = array_filter(array_unique(array_merge($school_ids_ed,$school_ids_1))); 
		}
		//$school_list = Db::name("school")->where('id','in',$school_ids_ed)->column('school_uuid,id');
		//$school_uuids_ed = array_keys($school_list);
		$school_list = Db::name("school")->where('id','in',$school_ids_ed)->field('school_uuid,id,school_suoshu,college_code,ranking,school_type')->select();
		$school_uuids_ed = array_column($school_list,'school_uuid');
		$school_suoshu_ed = array_column($school_list,'school_suoshu','school_uuid');
		$school_id_ed = array_column($school_list,'id','school_uuid');
		$school_code_ed = array_column($school_list,'college_code','id');
		$school_rank_ed = array_column($school_list,'ranking','id');
		$school_type_ed = array_column($school_list,'school_type','school_uuid');
		//dump($school_list);die;
		$school_tese = Db::name('school_tese_data')->alias('d')->join('school_tese t','d.tese_id=t.id')->where('d.school_id','in',$school_ids_ed)->field('d.school_id,t.title')->select();
		$school_tese_new = [];
		foreach($school_tese as $kt=>$vt){
			$school_tese_new[$vt['school_id']][] = $vt['title'];
			
		}
		//$school_type_ed = Db::name('school_type_data')->alias('d')->join('school_type t','d.type_id=t.id')->where('d.school_id','in',$school_ids_ed)->column('d.school_id,t.title');
		$school_type_arr = Db::name('school_type')->column('id,title');
       
		$enrollprovince = Db::name("area")->where('id',$province_id)->value('name');
		$year = date('Y',strtotime("-1 year"));
		$member = Db::name("member")->field('province_id,cj_score,cj_subjects,cj_subjects1,cj_subject_mode,cj_subject_mode_title,cj_rank')->where('id',$user_id)->find();
		if(empty($score_min)){
			$score_min = $member['cj_score']-30;
		}
		if(empty($score_max)){
			$score_max = $member['cj_score']+20;
		}
		if($score_min<$member['cj_score']-80){
			return $this->show(2001,"最低分".($member['cj_score']-80), '');
		}
		if($score_max>$member['cj_score']+50){
			return $this->show(2001,"最高分".($member['cj_score']+50), '');
		}
		$type = $member['cj_subject_mode_title'];
		if($batch == 1){
			$batchname = SchoolModel::getBenkeBtachs();
			$batch_score_name = '本科';
		}elseif($batch == 2){
			$batchname = SchoolModel::getZhuankeBtachs();
			$batch_score_name = '专科';
		}else{
			return $this->show(2001,"参数batch错误!", '');
		}
		
		//$end_time = microtime(true);//计时
		//echo "执行时间: " . ($end_time - $start_time) . " 秒";die;
						
		$batch_score = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year)->value('socre');//批次分数
		$year1 = date('Y',strtotime("-2 year"));
		$year2 = date('Y',strtotime("-3 year"));
		$batch_score1 = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year1)->value('socre');//批次分数
		$batch_score2 = Db::name("batch_line")->where('batch_name',$batch_score_name)->where('province_id',$province_id)->where('year',$year2)->value('socre');//批次分数
		//dump($school_uuids_ed);die;
		//去年院校数据
		$result = GuguService::make('/metadata/college-score-detail',['appkey'=>'CDZUAX7XAL84GKX9T96PULXVZMYLV8DQ','pageIndex'=>$page,'pageSize'=>$pagesize,'searchType'=>'PROVINCENAME','keyword'=>$enrollprovince,'year'=>$year,'highestScore'=>$score_max,'lowestScore'=>$score_min,'subjectSelection'=>$type,'batchName'=>$batchname]);
		if($result[0] != 200){
            return $this->show(2002,$result[1]??'error', '');
		}
		$list = $result[1][1];
		$count = $result[1][0]['DataTotalCount'];
		//$count = count($list);
		foreach($list as $k=>$v){
			if(empty($batch_score)){
				$linecha = '-';
			}else{
				if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
					$linecha = $v['LowestScore']-$batch_score;
				}else{
					$linecha = '-';
				}
			}
			if(empty($batch_score1)){
				$linecha1 = '-';
			}else{
				if(!empty($v['LowestScore_1']) && is_numeric($v['LowestScore_1'])){
					$linecha1 = $v['LowestScore_1']-$batch_score1;
				}else{
					$linecha1 = '-';
				}
			}
			if(empty($batch_score2)){
				$linecha2 = '-';
			}else{
				if(!empty($v['LowestScore_2']) && is_numeric($v['LowestScore_2'])){
					$linecha2 = $v['LowestScore_2']-$batch_score2;
				}else{
					$linecha2 = '-';
				}
			}
			
			if(empty($member['cj_rank'])){
				$dengxiao_weicha = '-';
			}else{
				if(!empty($v['LowestSection']) && is_numeric($v['LowestSection'])){
					$dengxiao_weicha = $v['LowestSection']-$member['cj_rank'];
				}else{
					$dengxiao_weicha = '-';
				}
			}
			if(empty($member['cj_rank'])){
				$dengxiao_weicha1 = '-';
			}else{
				if(!empty($v['LowestSection_1']) && is_numeric($v['LowestSection_1'])){
					$dengxiao_weicha1 = $v['LowestSection_1']-$member['cj_rank'];
				}else{
					$dengxiao_weicha1 = '-';
				}
			}
			
			if(empty($member['cj_rank'])){
				$dengxiao_weicha2 = '-';
			}else{
				if(!empty($v['LowestSection_2']) && is_numeric($v['LowestSection_2'])){
					$dengxiao_weicha2 = $v['LowestSection_2']-$member['cj_rank'];
				}else{
					$dengxiao_weicha2 = '-';
				}
			}
			 
			$list[$k]['CollegeTags'] = '';
			$list[$k]['school_suoshu'] = '';
			$list[$k]['dengxiao_weicha'] = $dengxiao_weicha;
			$list[$k]['dengxiao_weicha_1'] = $dengxiao_weicha1;
			$list[$k]['dengxiao_weicha_2'] = $dengxiao_weicha2;
			$list[$k]['linecha'] = $linecha;
			$list[$k]['linecha_1'] = $linecha1;
			$list[$k]['linecha_2'] = $linecha2;
			
			$MajorListNew = $v['MajorList'];
			foreach($MajorListNew as $k1=>$v1){
				if(empty($batch_score)){
					$linecha = '-';
				}else{
					if(!empty($v['LowestScore']) && is_numeric($v['LowestScore'])){
						$linecha = $v['LowestScore']-$batch_score;
					}else{
						$linecha = '-';
					}
				}
				if(empty($batch_score1)){
					$linecha1 = '-';
				}else{
					if(!empty($v['LowestScore_1']) && is_numeric($v['LowestScore_1'])){
						$linecha1 = $v['LowestScore_1']-$batch_score1;
					}else{
						$linecha1 = '-';
					}
				}
				if(empty($batch_score2)){
					$linecha2 = '-';
				}else{
					if(!empty($v['LowestScore_2']) && is_numeric($v['LowestScore_2'])){
						$linecha2 = $v['LowestScore_2']-$batch_score2;
					}else{
						$linecha2 = '-';
					}
				}
				
				if(empty($member['cj_rank'])){
					$dengxiao_weicha = '-';
				}else{
					if(!empty($v['LowestSection']) && is_numeric($v['LowestSection'])){
						$dengxiao_weicha = $v['LowestSection']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				if(empty($member['cj_rank'])){
					$dengxiao_weicha1 = '-';
				}else{
					if(!empty($v['LowestSection_1']) && is_numeric($v['LowestSection_1'])){
						$dengxiao_weicha = $v['LowestSection_1']-$member['cj_rank'];
					}else{
						$dengxiao_weicha = '-';
					}
				}
				
				if(empty($member['cj_rank'])){
					$dengxiao_weicha2 = '-';
				}else{
					if(!empty($v['LowestSection_2']) && is_numeric($v['LowestSection_2'])){
						$dengxiao_weicha2 = $v['LowestSection_2']-$member['cj_rank'];
					}else{
						$dengxiao_weicha2 = '-';
					}
				}
				$MajorListNew[$k]['dengxiao_weicha'] = $dengxiao_weicha;
				$MajorListNew[$k]['dengxiao_weicha_1'] = $dengxiao_weicha1;
				$MajorListNew[$k]['dengxiao_weicha_2'] = $dengxiao_weicha2;
				$MajorListNew[$k]['linecha'] = $linecha;
				$MajorListNew[$k]['linecha_1'] = $linecha1;
				$MajorListNew[$k]['linecha_2'] = $linecha2;
			}
			$list[$k]['MajorList'] = $MajorListNew;
		}
		
		
		$count_real = count($list);//过滤后真实数量
		
		
		//dump($list_new);die;
		
		$pages = ceil($count/$pagesize);
		if($pages == 1){
			$count = $count_real;
		}
        $data = array('list'=>$list,'count'=>$count,'pages'=>$pages,'pagesize'=>$pagesize);	
		return $this->show(1,"成功", $data);
		
    }
}